from db.aiomysql_connector import AioMysqlClient
from logger_config import logger
from services.cache_service import CacheUtils


class StationService(object):
    table = 'Station'

    def __init__(self):
        self.sql_client: AioMysqlClient = CacheUtils.get('aiomysql_pool')

    async def get_check_result(self):
        try:
            sql = f"select * from {self.table} order by id desc limit 1"
            latest_data = await self.sql_client.fetch_one(sql)
            semi_finished = latest_data['data600']
            finished = latest_data['data601']
            semi_finished = [int(i) for i in semi_finished]
            finished = [int(i) for i in finished]
        except Exception as e:
            semi_finished, finished = [], []
            logger.error(e)
        return semi_finished, finished
